<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "user_log".
 *
 * @property integer $id
 * @property integer $user_id
 * @property string $action
 * @property string $entry
 * @property double $current_currency
 * @property double $currency_change
 * @property string $create_at
 * @property string $update_at
 *
 * @property User $user
 */
class UserLog extends \app\models\BaseModel {
    /**
     * @inheritdoc
     */
    public static function tableName() {
        return 'user_log';
    }

    /**
     * @inheritdoc
     */
    public function rules() {
        return [
            [['user_id'], 'required'],
            [['user_id'], 'integer'],
            [['current_currency', 'currency_change'], 'number'],
            [['create_at', 'update_at'], 'safe'],
            [['action', 'entry'], 'string', 'max' => 255],
            [['user_id'], 'exist', 'skipOnError' => true, 'targetClass' => User::className(), 'targetAttribute' => ['user_id' => 'id']],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels() {
        return [
            'id' => 'ID',
            'user_id' => 'User ID',
            'action' => '操作',
            'entry' => '操作的对象',
            'current_currency' => 'Current Currency',
            'currency_change' => 'Currency Change',
            'create_at' => '创建时间',
            'update_at' => '更新时间',
        ];
    }

    public function fields() {
        $fields = [
        ];
        $fields = array_combine($fields, $fields);

        return $fields;
    }

    public function extraFields() {
        $fields = [
            'id',
            'user_id',
            'action',
            'entry',
            'current_currency',
            'currency_change',
            'create_at',
            'update_at',
        ];
        $fields = array_combine($fields, $fields);
        return $fields;
    }

    public function getUser() {
        return $this->hasOne(User::className(), ['id' => 'user_id'])->inverseOf('userLogs');
    }
}
